package tec.stan.ling.topo.model;

import org.xmappr.Attribute;

import tec.stan.ling.core.notifier.Notification;
import tec.stan.ling.core.notifier.impl.NotificationImpl;
import tec.stan.ling.core.top.model.Device;
import tec.stan.ling.core.top.model.Link;
import tec.stan.ling.core.top.model.NEState;
import tec.stan.ling.topo.demo.DeviceConverter;

/**
 * An extensible Link implementation.
 * 
 * @author Stan 张新潮
 * @date Jan 13, 2010
 */
public class LinkImpl extends NEImpl implements Link {

	@Attribute(converter = DeviceConverter.class)
	private Device leftDevice;

	@Attribute(converter = DeviceConverter.class)
	private Device rightDevice;

	private NEState state;

	public LinkImpl(int id, Device leftDevice, Device rightDevice) {
		this.id = id;
		this.leftDevice = leftDevice;
		this.rightDevice = rightDevice;
		// this.type
	}

	@Override
	public Device getTarget() {
		return leftDevice;
	}

	@Override
	public Device getSource() {
		return rightDevice;
	}

	@Override
	public NEState getState() {
		return state;
	}

	@Override
	public void serState(NEState state) {
		NEState oldState = this.state;
		this.state = state;
		if (isDeliver()) {
			notify(new NotificationImpl(this, Notification.SET,
					Link.LINK_STATE, oldState, oldState));
		}
	}
}
